package com.sws.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sws.domain.PaperState;
import com.sws.domain.PrizeState;
import com.sws.domain.State;
import com.sws.mapping.PrizeMapper;
import com.sws.mapping.PrizeStateMapper;
import com.sws.mapping.StateMapper;
import com.sws.model.bean.B2SPrizePageBean;
import com.sws.model.bean.B2SPrizeReviewBean;
import com.sws.model.bean.C2SPageBean;
import com.sws.model.bean.C2SPrizeBean;
import com.sws.model.bean.S2BPrizeBean;
import com.sws.model.bean.S2CPrizeBean;
import com.sws.service.PrizeService;

@Service
public class PrizeServiceImpl implements PrizeService {
	
	@Autowired
	private PrizeMapper mapper;
	@Autowired
	private StateMapper stateMapper;
	@Autowired
	private PrizeStateMapper prizeStateMapper;

	@Override
	public void uploadPrize(C2SPrizeBean bean) {
		// TODO Auto-generated method stub
		mapper.uploadPrize(bean);
	}

	@Override
	public List<S2CPrizeBean> getPersonalPrize(C2SPageBean pageBean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("user", pageBean.getUser());
		map.put("skips", (pageBean.getPages()-1)*pageBean.getLimits());
		map.put("limits", pageBean.getLimits());
		return mapper.getPersonalPrize(map);
	}

	@Override
	public void prizeReview(B2SPrizeReviewBean bean) {
		// TODO Auto-generated method stub
		State stateRecord = new State();
		stateRecord.setName(bean.getState());
		List<State> stateList = stateMapper.selectByExample(stateRecord);
		PrizeState prizeStateRecord = new PrizeState();
		prizeStateRecord.setId(bean.getPrize());
		List<PrizeState> paperStateList = prizeStateMapper.selectByExample(prizeStateRecord);
		prizeStateRecord = paperStateList.get(0);
		prizeStateRecord.setState(stateList.get(0).getId());
		prizeStateRecord.setOpinion(bean.getOpinion());
		prizeStateMapper.updateByPrimaryKeySelective(prizeStateRecord);
	}

	@Override
	public List<S2BPrizeBean> getAllPrize(B2SPrizePageBean bean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("skips", (bean.getPages()-1)*bean.getLimits());
		map.put("limits", bean.getLimits());
		map.put("yearStart", bean.getYearStart());
		map.put("yearEnd", bean.getYearEnd());
		map.put("level", bean.getLevel());
		map.put("grade", bean.getGrade());
		map.put("clazz", bean.getClazz());
		map.put("no", bean.getNo());
		map.put("name", bean.getName());
		return mapper.getAllPrize(map);
	}

}
